home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 5579 / 5579.xpi / components / piclensjshelper.js < prev   
Text File  |  2010-01-06  |  4KB  |  112 lines

  1. // Copyright 2008-2009, Cooliris Inc.
  2.  
  3. function PicLensJSHelper() {}
  4.  
  5. PicLensJSHelper.prototype = {
  6.     xpiPath getter: function() {
  7.         return __LOCATION__.parent.parent.path;
  8.     },
  9.     frontDocument getter: function() {
  10.         var tabBrowser = this._frontTabBrowser();
  11.         if (tabBrowser) {
  12.             var tab = tabBrowser.selectedBrowser;
  13.             return tab.contentDocument;
  14.         } else {
  15.             return null;
  16.         }
  17.     },
  18.     openUrl: function(url, newTab, selectTab) { 
  19.         var tabBrowser = this._frontTabBrowser();
  20.         if (!tabBrowser) {
  21.             return;
  22.         }
  23.         if (newTab) {
  24.             var tab = tabBrowser.addTab(url);
  25.             if (selectTab) tabBrowser.selectedTab = tab;
  26.         } else {
  27.             tabBrowser.selectedBrowser.contentDocument.location = url;
  28.         }
  29.     },
  30.     openHiddenBrowser: function(url) {
  31.         var tabBrowser = this._frontTabBrowser();
  32.         if (!tabBrowser) {
  33.             return null;
  34.         }
  35.  
  36.         var browser = tabBrowser.ownerDocument.createElementNS(
  37.             "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "browser");
  38.         browser.setAttribute("type", "content");
  39.         browser.setAttribute("src", url);
  40.         // For debugging:
  41.         // browser.setAttribute("style", "width: 300px;");
  42.         browser.setAttribute("style", "display: none;");
  43.         tabBrowser.appendChild(browser);
  44.         return browser;
  45.     },
  46.     closeHiddenBrowser: function(browser) {
  47.         var tabBrowser = this._frontTabBrowser();
  48.         if (!tabBrowser) {
  49.             return;
  50.         }
  51.         tabBrowser.removeChild(browser);
  52.     },
  53.     setToolbarLaunchIcon: function(win, doc, name) {
  54.         var button = win.document.getElementById('piclens-toolbarbutton2');
  55.         var selectedDoc = win.getBrowser().selectedBrowser.contentDocument;
  56.         if (button && doc === selectedDoc) {
  57.             button.className = "cooliris-toolbarbutton-" + name;
  58.         }
  59.     },
  60.     isBrowserForDocument: function(browser, doc) {
  61.         return (browser.contentDocument === doc);
  62.     },  
  63.     getUserAgentString: function(win) {
  64.         return win.navigator.userAgent;
  65.     },
  66.     _frontTabBrowser: function() {
  67.         var mediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  68.             .getService(Components.interfaces.nsIWindowMediator);
  69.         var win = mediator.getMostRecentWindow("navigator:browser");
  70.         return win ? win.getBrowser() : null;
  71.     },
  72.     QueryInterface: function(iid) {
  73.         if (!iid.equals(Components.interfaces.IPicLensJSHelper) &&
  74.             !iid.equals(Components.interfaces.nsISupports))
  75.             throw Components.results.NS_ERROR_NO_INTERFACE;
  76.         return this;
  77.     }
  78. };
  79.  
  80. var PicLensJSHelperModule = {
  81.     registerSelf: function(compMgr, fileSpec, location, type) {
  82.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  83.         compMgr.registerFactoryLocation(this.classId, this.className, this.contractId,
  84.             fileSpec, location, type);
  85.     },
  86.     getClassObject: function(compMgr, cid, iid) {
  87.         if (!cid.equals(this.classId))
  88.             throw Components.results.NS_ERROR_NO_INTERFACE;
  89.         if (!iid.equals(Components.interfaces.nsIFactory))
  90.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  91.         return this.factory;
  92.     },
  93.     canUnload: function(compMgr) {
  94.         return true;
  95.     },
  96.     
  97.     classId: Components.ID("a0ff7c31-77e1-4d6a-a6c6-c312ec2fbed4"),
  98.     className: "PicLensJSHelper",
  99.     contractId: "@cooliris.com/piclens/jshelper;1",
  100.     factory: {
  101.         createInstance: function(outer, iid) {
  102.             if (outer != null)
  103.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  104.             return (new PicLensJSHelper()).QueryInterface(iid);
  105.         }
  106.     }
  107. };
  108.  
  109. function NSGetModule(compMgr, fileSpec) {
  110.     return PicLensJSHelperModule;
  111. }
  112.